package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.logistic.domain.*;
import com.ruoyi.logistic.domain.vo.NetworkSheetPriceClientVo;
import com.ruoyi.logistic.domain.vo.NetworkSheetPriceContractVo;
import com.ruoyi.logistic.domain.vo.NetworkSheetPriceSalesmanVo;
import com.ruoyi.logistic.domain.vo.NetworkSheetPriceUnderpayVo;
import com.ruoyi.logistic.service.NetworkSheetPriceClientService;
import com.ruoyi.logistic.service.NetworkSheetPriceContractService;
import com.ruoyi.logistic.service.NetworkSheetPriceSalesmanService;
import com.ruoyi.logistic.service.NetworkSheetPriceUnderpayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.util.List;

@RestController
@RequestMapping("/networkSheetPrice")
@Api(tags = "网点财务_面单费报价")
public class NetworkSheetPriceController {
    @Autowired
    private NetworkSheetPriceClientService networkSheetPriceClientService;
    @Autowired
    private NetworkSheetPriceSalesmanService networkSheetPriceSalesmanService;
    @Autowired
    private NetworkSheetPriceContractService networkSheetPriceContractService;
    @Autowired
    private NetworkSheetPriceUnderpayService networkSheetPriceUnderpayService;

    @ApiOperation("显示客户价格列表")
    @GetMapping("/client/selectAll")
    public R selectClientAll(PageDate pageDate) {
        List<NetworkSheetPriceClient> networkSheetPriceClientList = networkSheetPriceClientService.selectAll(pageDate);
        if (networkSheetPriceClientList == null || networkSheetPriceClientList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceClientList));
        }
    }

    @ApiOperation("搜索客户价格列表")
    @PostMapping("/client/search")
    public R searchClient(@RequestBody NetworkSheetPriceClientVo vo) {

        // if (vo.getClientCode().equals("")){
        //     vo.setClientCode(null);
        // }else if (vo.getClientName().equals("")){
        //     vo.setClientName(null);
        // }else if (vo.getClientScreen().equals("")){
        //     vo.setClientScreen(null);
        // }else if (vo.getNetworkNameId().equals("")){
        //     vo.setNetworkNameId(null);
        // }else if (vo.getNickName().equals("")){
        //     vo.setNickName(null);
        // }else if (vo.getParentClientId().equals("")){
        //     vo.setParentClientId(null);
        // }else if (vo.getClientType().equals("")){
        //     vo.setClientType(null);
        // }else if (vo.getObjectName().equals("")){
        //     vo.setObjectName(null);
        // }else if (vo.getClientSourceId().equals("")){
        //     vo.setClientSourceId(null);
        // }else if (vo.getClientStatus().equals("")){
        //     vo.setClientStatus(null);
        // }


        List<NetworkSheetPriceClient> networkSheetPriceClientList = networkSheetPriceClientService.search(vo);
        if (networkSheetPriceClientList == null || networkSheetPriceClientList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceClientList));
        }
    }

    @ApiOperation("添加客户价格")
    @PostMapping("/client/insert")
    public R insertClient(@RequestBody NetworkSheetPriceClient networkSheetPriceClient) {
        Boolean isAdd = networkSheetPriceClientService.insert(networkSheetPriceClient);
        if (isAdd) {
            return R.ok("添加成功");
        } else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改客户价格")
    @PostMapping("/client/update")
    public R updateClient(@RequestBody NetworkSheetPriceClient networkSheetPriceClient) {
        Boolean isUpdate = networkSheetPriceClientService.update(networkSheetPriceClient);
        if (isUpdate) {
            return R.ok("修改成功");
        } else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除客户价格")
    @PostMapping("/client/deleteById")
    public R deleteClient(Integer id) {
        Boolean isDelete = networkSheetPriceClientService.deleteById(id);
        if (isDelete) {
            return R.ok("删除成功");
        } else {
            return R.fail("删除失败");
        }
    }

    //    @ApiOperation("批量修改客户价格")
//    @PostMapping("/client/updateList")
//    public R updateClientList(@Param("clientStatus") String clientStatus , ){
//
//    }
    @ApiOperation("显示业务员价格列表")
    @GetMapping("/salesman/selectAll")
    public R selectSalesmanAll(PageDate pageDate) {
        List<NetworkSheetPriceSalesman> networkSheetPriceSalesmanList = networkSheetPriceSalesmanService.selectAll(pageDate);
        if (networkSheetPriceSalesmanList == null || networkSheetPriceSalesmanList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceSalesmanList));
        }
    }

    @ApiOperation("添加业务员价格")
    @PostMapping("/salesman/insert")
    public R insertSalesman(@RequestBody NetworkSheetPriceSalesman networkSheetPriceSalesman) {
        Boolean isAdd = networkSheetPriceSalesmanService.insert(networkSheetPriceSalesman);
        if (isAdd) {
            return R.ok("添加成功");
        } else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改业务员价格")
    @PostMapping("/salesman/update")
    public R updateSalesman(@RequestBody NetworkSheetPriceSalesman networkSheetPriceSalesman) {
        Boolean isUpdate = networkSheetPriceSalesmanService.update(networkSheetPriceSalesman);
        if (isUpdate) {
            return R.ok("修改成功");
        } else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除业务员价格")
    @PostMapping("/salesman/deleteById")
    public R deleteSalesman(Integer id) {
        Boolean isDelete = networkSheetPriceSalesmanService.deleteById(id);
        if (isDelete) {
            return R.ok("删除成功");
        } else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("搜索业务员列表")
    @PostMapping("/salesman/search")
    public R searchSalesman(@RequestBody NetworkSheetPriceSalesmanVo vo){
        List<NetworkSheetPriceSalesman> networkSheetPriceSalesmanList = networkSheetPriceSalesmanService.search(vo);
        if (networkSheetPriceSalesmanList == null || networkSheetPriceSalesmanList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceSalesmanList));
        }
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @ApiOperation("导出业务员价格")
    @GetMapping("/salesman/export")
    public AjaxResult export(PageDate pageDate) {
        List<NetworkSheetPriceSalesman> list = networkSheetPriceSalesmanService.selectAll(pageDate);
        ExcelUtil<NetworkSheetPriceSalesman> util = new ExcelUtil<NetworkSheetPriceSalesman>(NetworkSheetPriceSalesman.class);
        return util.exportExcel(list, "业务员价格数据");
    }

    @ApiOperation("查询业务员修改修改记录明细")
    @GetMapping("/salesman/detail")
    public R searchSalesmanDetail(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("id") Integer id) {
        List<NetworkSheetPriceSalesmanRecord> records = networkSheetPriceSalesmanService.searchDetail(startTime, endTime, id);
        if (records == null || records.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(records));
        }
    }

    @ApiOperation("显示承包区价格列表")
    @GetMapping("/contract/selectAll")
    public R selectContractAll(PageDate pageDate) {
        List<NetworkSheetPriceContract> networkSheetPriceContractList = networkSheetPriceContractService.selectAll(pageDate);
        if (networkSheetPriceContractList == null || networkSheetPriceContractList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceContractList));
        }
    }

    @ApiOperation("搜索承包区价格")
    @PostMapping("/contract/search")
    public R searchContract(@RequestBody NetworkSheetPriceContractVo vo){
        List<NetworkSheetPriceContract> networkSheetPriceContractList = networkSheetPriceContractService.search(vo);
        if (networkSheetPriceContractList == null || networkSheetPriceContractList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceContractList));
        }
    }

    @ApiOperation("添加承包区价格")
    @PostMapping("/contract/insert")
    public R insertContract(@RequestBody NetworkSheetPriceContract networkSheetPriceContract) {
        Boolean isAdd = networkSheetPriceContractService.insert(networkSheetPriceContract);
        if (isAdd) {
            return R.ok("添加成功");
        } else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改承包区价格")
    @PostMapping("/contract/update")
    public R updateContract(@RequestBody NetworkSheetPriceContract networkSheetPriceContract) {
        Boolean isUpdate = networkSheetPriceContractService.update(networkSheetPriceContract);
        if (isUpdate) {
            return R.ok("修改成功");
        } else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除承包区价格")
    @PostMapping("/contract/deleteById")
    public R deleteContract(Integer id) {
        Boolean isDelete = networkSheetPriceContractService.deleteById(id);
        if (isDelete) {
            return R.ok("删除成功");
        } else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("查询承包区价格修改记录明细")
    @GetMapping("/contract/detail")
    public R searchContractDetail(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("id") Integer id) {
        List<NetworkSheetPriceContractRecord> records = networkSheetPriceContractService.searchDetail(startTime, endTime, id);
        if (records == null || records.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(records));
        }
    }
    @ApiOperation("显示兜底价格列表")
    @GetMapping("/underpay/selectAll")
    public R selectUnderpayAll(PageDate pageDate) {
        List<NetworkSheetPriceUnderpay> networkSheetPriceUnderpayList = networkSheetPriceUnderpayService.selectAll(pageDate);
        if (networkSheetPriceUnderpayList == null || networkSheetPriceUnderpayList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceUnderpayList));
        }
    }

    @ApiOperation("搜索兜底价格")
    @PostMapping("/underpay/search")
    public R searchUnderpay(@RequestBody NetworkSheetPriceUnderpayVo vo){
        List<NetworkSheetPriceUnderpay> networkSheetPriceUnderpayList = networkSheetPriceUnderpayService.search(vo);
        if (networkSheetPriceUnderpayList == null || networkSheetPriceUnderpayList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(networkSheetPriceUnderpayList));
        }
    }

    @ApiOperation("添加兜底价格")
    @PostMapping("/underpay/insert")
    public R insertUnderpay(@RequestBody NetworkSheetPriceUnderpay networkSheetPriceUnderpay) {
        Boolean isAdd = networkSheetPriceUnderpayService.insert(networkSheetPriceUnderpay);
        if (isAdd) {
            return R.ok("添加成功");
        } else {
            return R.fail("添加失败");
        }
    }

    @ApiOperation("修改兜底价格")
    @PostMapping("/underpay/update")
    public R updateUnderpay(@RequestBody NetworkSheetPriceUnderpay networkSheetPriceUnderpay) {
        Boolean isUpdate = networkSheetPriceUnderpayService.update(networkSheetPriceUnderpay);
        if (isUpdate) {
            return R.ok("修改成功");
        } else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除兜底价格")
    @PostMapping("/underpay/deleteById")
    public R deleteUnderpay(Integer id) {
        Boolean isDelete = networkSheetPriceUnderpayService.deleteById(id);
        if (isDelete) {
            return R.ok("删除成功");
        } else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("查询兜底价格修改记录明细")
    @GetMapping("/underpay/detail")
    public R searchUnderpayDetail(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("id") Integer id) {
        List<NetworkSheetPriceUnderpayRecord> records = networkSheetPriceUnderpayService.searchDetail(startTime, endTime, id);
        if (records == null || records.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(PageInfo.info(records));
        }
    }
}
